/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bo;

import java.util.*;

/**
 *
 * @author 47
 */
public class MenuItem implements Comparator {

    public MenuItem() {
        this.children=new ArrayList();
    }
    private String menuHTML=null;
    private String menuName = "";
    private String menuURI = "";
    private List children;
    private long menuId = -1;
    private long parentId = -1;
    private long orderCode=99;

    public int compare(Object o1, Object o2) {
        //throw new UnsupportedOperationException("Not supported yet.");
        bo.MenuItem item1=(bo.MenuItem) o1;
        bo.MenuItem item2=(bo.MenuItem) o2;
        if(item1.getOrderCode()>item2.getOrderCode()){
            return 1;
        }else{
            return -1;
        }
    }

    public String composeHTML(){
        String idStr=String.valueOf(this.getMenuId());
        this.setMenuHTML("<td style=\"width:inherit;border-left:none;border-right:none;\">");
        this.setMenuHTML(this.getMenuHTML() + "<div style=\"position:relative;z-index:0;\"><!--层-->");
        this.setMenuHTML(this.getMenuHTML() + "<div style=\"text-align:left;text-decoration:underline\" id=\"menu" + idStr + "\" onmouseover=\"showMenu(" + idStr + ")\">");
        this.setMenuHTML(this.getMenuHTML() + this.menuName+"</div>");
        this.setMenuHTML(this.getMenuHTML() + "<div id=\"menuitem" + idStr + "\" onmouseover=\"showMenu(" + idStr + ")\" onmouseout=\"hideMenu(" + idStr + ")\"");
        this.setMenuHTML(this.getMenuHTML() + "style=\"display:none;position:absolute;top:0px;left:0px;z-index:10;\"><!--菜单层-->");
        this.setMenuHTML(this.getMenuHTML() + "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><!--放置菜单-->");
        this.setMenuHTML(this.getMenuHTML() + "<tr><td>&nbsp;</td></tr>");
        this.setMenuHTML(this.getMenuHTML() + "<tr><td>");
        this.setMenuHTML(this.getMenuHTML() + "<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"width:100px;\">");
        Iterator itr=this.getChildren().iterator();
        MenuItem item=null;
        while(itr.hasNext()){
            item=(MenuItem)itr.next();
            this.setMenuHTML(this.getMenuHTML() + "<tr><td style=\"background-color:white;\"><a class=\"menu_item\" href=\"" + item.getMenuURI() + "?f="+item.getMenuId()+"\">"+item.getMenuName()+"</a></td></tr>");
        }
        this.setMenuHTML(this.getMenuHTML() + "</table>");
        this.setMenuHTML(this.getMenuHTML() + "</td>");
        this.setMenuHTML(this.getMenuHTML() + "</tr>");
        this.setMenuHTML(this.getMenuHTML() + "</table><!--放置菜单-->");
        this.setMenuHTML(this.getMenuHTML() + "</div><!--菜单层-->");
        this.setMenuHTML(this.getMenuHTML() + "</div><!--层-->");
        this.setMenuHTML(this.getMenuHTML() + "</td>");
        return this.getMenuHTML();
    }

    /**
     * @return the menuHTML
     */
    public String getMenuHTML() {
        return menuHTML;
    }

    /**
     * @param menuHTML the menuHTML to set
     */
    public void setMenuHTML(String menuHTML) {
        this.menuHTML = menuHTML;
    }

    /**
     * @return the menuName
     */
    public String getMenuName() {
        return menuName;
    }

    /**
     * @param menuName the menuName to set
     */
    public void setMenuName(String menuName) {
        this.menuName = menuName;
    }

    /**
     * @return the menuURI
     */
    public String getMenuURI() {
        return menuURI;
    }

    /**
     * @param menuURI the menuURI to set
     */
    public void setMenuURI(String menuURI) {
        this.menuURI = menuURI;
    }

    /**
     * @return the children
     */
    public List getChildren() {
        return children;
    }

    /**
     * @param children the children to set
     */
    public void setChildren(List children) {
        this.children = children;
    }

    /**
     * @return the menuId
     */
    public long getMenuId() {
        return menuId;
    }

    /**
     * @param menuId the menuId to set
     */
    public void setMenuId(long menuId) {
        this.menuId = menuId;
    }

    /**
     * @return the parentId
     */
    public long getParentId() {
        return parentId;
    }

    /**
     * @param parentId the parentId to set
     */
    public void setParentId(long parentId) {
        this.parentId = parentId;
    }

    /**
     * @return the orderCode
     */
    public long getOrderCode() {
        return orderCode;
    }

    /**
     * @param orderCode the orderCode to set
     */
    public void setOrderCode(long orderCode) {
        this.orderCode = orderCode;
    }
}
